package dev.ece.suit.hexmap;

import dev.ece.util.lib.Vector2f;
import dev.ece.util.lib.Vector3f;

public class MapTriangle {
	
	/**
	 * direction == Direction.DIRECTION_0 : 0、左，1、右，2、上
	 * direction == Direction.DIRECTION_1 : 0、左，1、下，2、右
	 */
	private MapCell[] cells;
	
	/**
	 * direction == Direction.DIRECTION_0 : 0、左，1、右，2、上
	 * direction == Direction.DIRECTION_1 : 0、左，1、下，2、右
	 */
	private MapCrevice[] crevices;
	
	/**
	 * Direction.DIRECTION_0：上
	 * Direction.DIRECTION_1：下
	 */
	private int direction;
	
	private Vector3f[][] vertice;
	
	private Vector3f[][] normals;
	
	private Vector2f[][] uv;
	
	private Vector2f[][] alpha;
	
	private int first;
	
	public MapTriangle(
			MapCell[] cells, MapCrevice[] crevices, int direction,
			Vector3f[][] vertice, Vector3f[][] normals, Vector2f[][] uv, Vector2f[][] alpha, int first) {
		this.cells = cells;
		this.crevices = crevices;
		this.direction = direction;
		this.vertice = vertice;
		this.normals = normals;
		this.uv = uv;
		this.alpha = alpha;
		this.first = first;
	}
	
	protected void glShader(MapModel model, HexMapTriangleShader triangleShader) {
		triangleShader.glTexture(
				getCells()[0].getTerrain().texture(model.getTerrainModelCreator()), 
				getCells()[1].getTerrain().texture(model.getTerrainModelCreator()), 
				getCells()[2].getTerrain().texture(model.getTerrainModelCreator()));
		triangleShader.glMaterial(
				getCells()[0].getTerrain().getMaterial(), 
				getCells()[1].getTerrain().getMaterial(), 
				getCells()[2].getTerrain().getMaterial());
	}

	public void renderDepth(MapModel model) {
		model.getTerrainModelCreator().render(this);
	}

	public void render(MapModel model, HexMapTriangleShader triangleShader) {
		glShader(model, triangleShader);
		renderDepth(model);
	}

	public MapCell[] getCells() {
		return cells;
	}

	public MapCrevice[] getCrevices() {
		return crevices;
	}

	public int getDirection() {
		return direction;
	}

	public Vector3f[][] getVertice() {
		return vertice;
	}

	public Vector3f[][] getNormals() {
		return normals;
	}

	public Vector2f[][] getUv() {
		return uv;
	}

	public Vector2f[][] getAlpha() {
		return alpha;
	}

	public int getFirst() {
		return first;
	}
	
}
